﻿using System;
using System.Collections.Generic;
using Framework;

namespace Enterprise.Admin.Handle
{
    /// <summary>
    /// 获取文章详细
    /// </summary>
    public partial class GetArticleDetailJson : AdminBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var list = new List<object>();
            var id = Fq("id").SafeToInt();
            var articleService = new ArticleService();
            var row = articleService.GetById(id);
            object result = new
                                     {
                                         CoArticleId = row["CoArticleId"].SafeToString(),
                                         CoTitle = row["CoTitle"].SafeToString(),
                                         CoContent = row["CoContent"].SafeToString(),
                                         CoIsRecommend = row["CoIsRecommend"].SafeToBool(),
                                         CoDate = row["CoDate"].SafeToDateTime().ToString("yyyy-MM-dd HH:mm:ss"),
                                         CoSummary = row["CoSummary"].SafeToString(),
                                         CoIsPopular = row["CoIsRecommend"].SafeToBool(),
                                         CoIsTop = row["CoIsTop"].SafeToBool(),
                                         CoViews = row["CoViews"].SafeToInt(),
                                         CoIsReserved = row["CoLanguage"].SafeToBool(),
                                         CoReservedUrl = row["CoReservedUrl"].SafeToString(),
                                         CoArticleCategoryId = row["CoArticleCategoryId"].SafeToString(),
                                         CoCategoryPath = row["CoCategoryPath"].SafeToString(),
                                         CoLanguage = row["CoLanguage"].SafeToString(),
                                         ArticleImage = list
                                     };
            var articleImageService = new ArticleImageService();
            var dr = articleImageService.GetTable(id).Rows;
            for (int i = 0; i < dr.Count; i++)
            {

                list.Add(
                    new
                    {
                        id = dr[i]["CoArticleImageId"].SafeToInt(),
                        CoArticleImageId = dr[i]["CoArticleImageId"].SafeToInt(),
                        CoSmallImage = dr[i]["CoSmallImage"].SafeToString(),
                        CoNormalImage = dr[i]["CoNormalImage"].SafeToString(),
                        thumFileName = dr[i]["CoSmallImage"].SafeToString(),
                        CoBigImage = dr[i]["CoBigImage"].SafeToString(),
                    });

            }
            Json(result);
        }
    }
}